Convert inline image tags like [image:123:title:size] into HTML img tags

Posted by Jacques Joubert on Stack Overflow See other posts from Stack Overflow or by Jacques Joubert
Published on 2013-10-19T21:49:15Z Indexed on 2013/10/19 21:54 UTC
Read the original article Hit count: 260

Filed under:
|
|
|
|

I am looking for help with regular expression $pattern to convert inline image tags like [image:123:title:size] into HTML img tags.

here is the code:

//[image:ID:caption:size]
$content = '[image:38:title:800x900]';

preg_match_all( '/\[image:(\d+)(:?)([^\]]*)\]/i', $content, $images );

        if( !empty( $images[0] ) )
        {   // There are image inline tags in the content
            foreach( $images[0] as $i => $tag )
            {

                $link_ID = (int)$images[1][$i];
                $caption = empty( $images[2][$i] ) ? '#' : $images[3][$i];
                $size = empty( $images[4][$i] ) ? '#' : $images[4][$i];

            }
            echo '<br />';
            echo 'ID: '.$link_ID.'<br />';
            echo 'Tag: '.$caption.'<br />';
            echo 'size: '.$size.'<br />';
        }

which outputs:

ID: 12

Tag: caption:size

size: #

Any help would be great!

© Stack Overflow or respective owner

Related posts about php

Related posts about html